import { NotificationProps, ElNotification } from 'element-plus'
import { ResultType } from '@xtail/result'

type ElNotificationTypeWithoutType = Omit<Partial<NotificationProps>, 'type'>

export const ElSuccessNotification_Name = 'ElSuccessNotification'

export const ElSuccessNotification = (options: ElNotificationTypeWithoutType) => {
  ElNotification({
    type: 'success',
    ...options
  })
}

export const ElErrorNotification_Name = 'ElErrorNotification'

export const ElErrorNotification = (options: ElNotificationTypeWithoutType) => {
  ElNotification({
    type: 'error',
    ...options
  })
}

export const ElInfoNotification_Name = 'ElInfoNotification'

export const ElInfoNotification = (options: ElNotificationTypeWithoutType) => {
  ElNotification({
    type: 'info',
    ...options
  })
}

export const ElWarningNotification_Name = 'ElWarningNotification'

export const ElWarningNotification = (options: ElNotificationTypeWithoutType) => {
  ElNotification({
    type: 'warning',
    ...options
  })
}

export const ElNotificationByResult_Name = 'ElNotificationByResult'

export const ElNotificationByResult = (
  result: ResultType,
  options: Omit<ElNotificationTypeWithoutType, 'title' | 'message'> = {}
) => {
  if (result.status) {
    ElSuccessNotification({
      title: result.message,
      ...options
    })
  } else {
    ElErrorNotification({
      title: result.message,
      message: result.data,
      ...options
    })
  }
}
